// Copyright Epic Games, Inc. All Rights Reserved.

#include "LyraCharacterWithAbilities.h"

#include "AbilitySystem/Attributes/LyraCombatSet.h"
#include "AbilitySystem/Attributes/LyraHealthSet.h"
#include "AbilitySystem/LyraAbilitySystemComponent.h"
#include "Async/TaskGraphInterfaces.h"

#include UE_INLINE_GENERATED_CPP_BY_NAME(LyraCharacterWithAbilities)

/**
 * 构造函数
 */
ALyraCharacterWithAbilities::ALyraCharacterWithAbilities(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer) // 调用父类构造函数
{
	AbilitySystemComponent = ObjectInitializer.CreateDefaultSubobject<ULyraAbilitySystemComponent>(this, TEXT("AbilitySystemComponent")); // 创建能力系统组件
	AbilitySystemComponent->SetIsReplicated(true); // 设置是否复制
	AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed); // 设置复制模式

	// 这些属性集将被AbilitySystemComponent::InitializeComponent检测到。保留引用以便集合在初始化前不被垃圾回收。
	HealthSet = CreateDefaultSubobject<ULyraHealthSet>(TEXT("HealthSet")); // 创建健康集
	CombatSet = CreateDefaultSubobject<ULyraCombatSet>(TEXT("CombatSet")); // 创建战斗集

	// 能力系统组件需要高频更新。
	SetNetUpdateFrequency(100.0f); // 设置网络更新频率
}

/**
 * 后初始化组件
 */
void ALyraCharacterWithAbilities::PostInitializeComponents()
{
	Super::PostInitializeComponents(); // 调用父类方法

	check(AbilitySystemComponent); // 检查能力系统组件
	AbilitySystemComponent->InitAbilityActorInfo(this, this); // 初始化能力Actor信息
}

/**
 * 获取能力系统组件
 */
UAbilitySystemComponent* ALyraCharacterWithAbilities::GetAbilitySystemComponent() const
{
	return AbilitySystemComponent; // 返回能力系统组件
}